// pages/shoppingCart/childCpns/w-cart-bottom/w-cart-bottom.js

const app = getApp();

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isSelectAll: false,
    totalMoney: 0
  },
  observers: {
    'list': function (list) {
      let isSelectAll = !list.some(item => !item.checked);
      let totalMoney = list.filter(item => item.checked)
        .reduce((pre, item) => {
          return pre + item.price * item.purchaseCount
        }, 0).toFixed(2);
      this.setData({
        isSelectAll,
        totalMoney
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    checkboxChange(event) {
      app.changeSelectAll(event.detail.value.length > 0);
      this.triggerEvent("handleChangeGoods");
    }
  }
})